﻿using UnityEngine;
using System.Collections;

public class InGameText : MonoBehaviour {

    public GameObject m_pOwner;
    public string m_strText;

    float m_fSpeed;
	// Use this for initialization
	void Start () {
        transform.localScale = new Vector3(0.5f, 0.5f);

        m_fSpeed = 10.0f * Time.deltaTime;
        transform.GetChild(0).GetChild(0).GetComponent<UILabel>().text = m_strText;

        GetComponent<UIFollowTarget>().enabled = true;
        GetComponent<UIFollowTarget>().target = m_pOwner.transform;
        GetComponent<UIFollowTarget>().gameCamera = GameObject.Find("MainCamera").GetComponent<Camera>();
        GetComponent<UIFollowTarget>().uiCamera = GameObject.Find("Camera").GetComponent<Camera>();
	}
	
	// Update is called once per frame
	void Update () {
        if (GetComponent<UIFollowTarget>().target == null)
        {
            GetComponent<UIFollowTarget>().enabled = false;
        }

        transform.GetChild(0).localPosition = new Vector3(transform.GetChild(0).localPosition.x, transform.GetChild(0).localPosition.y + m_fSpeed);
        transform.GetChild(0).GetComponent<UISprite>().color = new Color(58 / 255f, 39 / 255f, 24 / 255f, transform.GetChild(0).GetComponent<UISprite>().color.a - 2 / 255f);

        if (transform.GetChild(0).GetComponent<UISprite>().color.a <= 0)
            Destroy(gameObject);
	}
}
